package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.lzx.iteam.AttendanceDevicesActivity;
import com.lzx.iteam.AttendanceWifiSettingActivity;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.DeviceMsgData;
import com.lzx.iteam.bean.WifiMsgData;

import java.util.ArrayList;

import static android.R.id.list;

/**
 * Created by Megan on 16/3/14.
 */
public class AttendanceWifiAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<WifiMsgData> datas;

    public AttendanceWifiAdapter(Context mContext) {
        this.mContext = mContext;

    }

    public void bindData(ArrayList<WifiMsgData> list) {
        this.datas = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas == null ? 0 : datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas == null ? null : datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder = null;
        final WifiMsgData wifiMsgData = datas.get(position);
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.attendance_wifi_list_item, null);
            holder.mTvName = (TextView) convertView.findViewById(R.id.tv_attendance_wifi_list_item_name);
            holder.mTvState = (TextView) convertView.findViewById(R.id.tv_attendance_wifi_list_item_state);
            holder.mIvDelete = (ImageView) convertView.findViewById(R.id.iv_attendance_wifi_list_item_delete);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mTvName.setText(wifiMsgData.getWifiName());
        holder.mTvState.setText("已设定");
        holder.mIvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((AttendanceWifiSettingActivity)mContext).deleteData(wifiMsgData);
            }
        });


        return convertView;
    }


    private class ViewHolder {
        TextView mTvName;
        TextView mTvState;
        ImageView mIvDelete;
    }

}
